package com.yaowk.sfp.login.server.controller;

import com.yaowk.sfp.common.base.PageReq;
import com.yaowk.sfp.common.base.PageResp;
import com.yaowk.sfp.login.api.LoginLogApi;
import com.yaowk.sfp.login.api.model.LoginLogModel;
import com.yaowk.sfp.login.server.service.ILoginLogService;
import com.yaowk.sfp.security.api.AuthApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "登录日志")
public class LoginLogController implements LoginLogApi {

    @Autowired
    private ILoginLogService loginLogService;
    @Autowired
    private AuthApi authApi;

    @Override
    @ApiOperation("日志列表")
    public PageResp<LoginLogModel> list(LoginLogModel loginLog, PageReq pageReq) {
        return loginLogService.findAll(loginLog, pageReq);
    }

    @Override
    @ApiOperation("我的登录日志")
    public PageResp<LoginLogModel> selfList(LoginLogModel loginLog, PageReq pageReq) {
        loginLog.setUserId(authApi.userInfo().getId());
        return loginLogService.findAll(loginLog, pageReq);
    }

    @Override
    @ApiOperation("保存登录日志")
    public LoginLogModel save(LoginLogModel loginLog) {
        return loginLogService.save(loginLog);
    }

    @Override
    @ApiOperation("删除登录日志")
    public void delete(@PathVariable Long id) {
        loginLogService.deleteById(id);
    }
}
